/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tkgarment.system.action;

import static com.opensymphony.xwork2.Action.SUCCESS;
import com.tkgarment.system.dao.DataFileDAO;
import com.tkgarment.system.domain.DataFile;
import com.tkgarment.system.factory.DAOFactory;
import java.util.List;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;

/**
 *
 * @author zraj
 */
public class EmpFileAction extends ActionSupportBase implements SessionAware {

    Map<String, Object> session;
    List<DataFile> files;
    Integer fileIdDelete;
    String empId;
    Integer activeTab = 2;
    
    
    
    public String execute() {

        try {
             empId = session.get("session_emp_id").toString();

            DataFileDAO dao = DAOFactory.createDataFileDao();

            setFiles(dao.getByEmpID(empId));
        } catch (Exception e) {
            e.printStackTrace();
            setMessage("ERROR : " + e.getMessage());
        }

        return "success";
    }

    public String deleteFile() {
        try {
            empId = session.get("session_emp_id").toString();
            activeTab = 2;
            DataFileDAO dao = DAOFactory.createDataFileDao();
            DataFile f = new DataFile();
            f.setFileId(fileIdDelete);
            dao.deleteSingle(f);
            return SUCCESS;
        } catch (Exception e) {
            setMessage(e.getMessage());
            return SUCCESS;
        }

    }

    public Integer getFileIdDelete() {
        return fileIdDelete;
    }

    public void setFileIdDelete(Integer fileIdDelete) {
        this.fileIdDelete = fileIdDelete;
    }

    public String getEmpId() {
        return empId;
    }

    public void setEmpId(String empId) {
        this.empId = empId;
    }
    
    

    public List<DataFile> getFiles() {
        return files;
    }

    public void setFiles(List<DataFile> files) {
        this.files = files;
    }

    @Override
    public void setSession(Map<String, Object> map) {
        this.session = map;
    }

    public Map<String, Object> getSession() {
        return session;
    }

    public Integer getActiveTab() {
        return activeTab;
    }

    public void setActiveTab(Integer activeTab) {
        this.activeTab = activeTab;
    }
    
    
}
